package com.jt.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.jt.pojo.Item;
import com.jt.pojo.ItemDesc;
import com.jt.service.DubboItemService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @Author: Li Yu
 * @Date: 2020/11/19 18:51
 */
@Controller
public class ItemController {
    @Reference
    private DubboItemService dubboItemService;


    /**
     * 实现商品的展现
     * url：www.jt.com/items/562379.html
     * 参数： 562379商品id号
     * 返回值：item.jsp
     * 页面取值：item对象 itemDesc对象
     */
    @RequestMapping("/items/{itemId}")
    public String findItemId(@PathVariable Long itemId, Model model){
        Item item=dubboItemService.findItemById(itemId);
        ItemDesc itemDesc=dubboItemService.findItemDescById(itemId);
        model.addAttribute("item", item);
        model.addAttribute("itemDesc", itemDesc);
        return "item";
    }
}
